package org.geektimes.projects.user.web.controller;

import org.geektimes.projects.user.domain.User;
import org.geektimes.projects.user.service.UserService;
import org.geektimes.projects.user.service.UserServiceImpl;
import org.geektimes.web.mvc.controller.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import java.util.Date;
import java.util.Map;

/**
 * @author guozhan
 * @description TODO
 * @date 2021/3/1 18:34
 */
@Path("/registerAction")
public class RegisterActionController implements RestController {


    private UserService userService = new UserServiceImpl();


    @Override
    @POST
    public String handleRequest(HttpServletRequest request, HttpServletResponse response) {
        Map<String, String[]> parameterMap = request.getParameterMap();

        String username = parameterMap.get("username")[0];
        String password = parameterMap.get("password")[0];
        String email = parameterMap.get("email")[0];
        String phoneNumber = parameterMap.get("phoneNumber")[0];
        User user = new User();
        user.setId(System.currentTimeMillis());
        user.setName(username);
        user.setPassword(password);
        user.setEmail(email);
        user.setPhoneNumber(phoneNumber);
        userService.register(user);

        return "register-success.jsp";
    }
}
